package com.car.util;

import java.util.List;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class DocUtil {

	static Logger logger = Logger.getLogger(DocUtil.class.getName());

	public static Document getDocProxy(String url, List<String> ipList, int index) {
		String ip[] = ipList.get(index).split(":");
		Document doc = null;
		int i = 0;
		while (i < 2) {
			try {
				doc = Jsoup.connect(url).proxy(ip[0], Integer.parseInt(ip[1])).timeout(30000).get();
				break;
			} catch (Exception e) {
				if (i == 1) {
					System.out.println(url);
				}
				i++;
			}
		}
		return doc;
	}

	public static Document getDoc(String url) {
		Document doc = null;
		int i = 0;
		while (i < 3) {
			try {
				doc = Jsoup.connect(url).timeout(30000).get();
				break;
			} catch (Exception e) {
				i++;
				if (i >= 3) {
					logger.info("连接5次连接失败：" + url);
					continue;
				}
			}
		}
		return doc;
	}

}
